import urls from '/util/urls'
import request from '/util/request'
import { parseTime } from '/util/utils'

Page({
  data: {
    tasks: [],
  },
  onLoad() {
    request.login(this.init.bind(this))
  },
  init() {
    const that = this
    const searchable = {
      s_published: true,
      s_todo: true,
      s_scope: 'WORKER'
    }
    request.get(urls.questionnaireUrl(), searchable, function(data){
      that.setData({
        tasks: data.map(it => {
          return {
            id: it.id,
            title: it.title,
            publishAt: parseTime(it.publishAt, '{y}-{m}-{d}')
          }
        })
      })
    })
  },
  onItemClick(e) {
    const id = e.index
    dd.navigateTo({
      url: '/pages/feedback/feedback?taskId=' + id
    })
  }
});
